var nowDate = getDay(0);
var pandianid = GetQueryString('pandianid');
var type = GetQueryString("type");//页面类型 chakan,queren,huifu,zongjie
var corp = GetQueryString('corp')==null?"":GetQueryString('corp');
var pandianLevel,everyId,shopcode;
var rate;
layui.use(['rate'], function(){
	 rate = layui.rate;
	});
if(corp==''){
	corp = sessionStorage.getItem("corp");
}else{
	sessionStorage.setItem("corp",corp);
}


var _config ;
$.ajax({
	type : "post",
	data:JSON.stringify({"pageUrl":location.href.replace(/\\&/g,'%26'),"corp":corp}),
	contentType: "application/json; charset=utf-8",
	async: false,
	url : "../../dingding/getconfig",
	dataType : "json",
	success : function(suc) {
		_config = suc.config;
	}
}); 
dd.config({
	agentId : _config.agentid,
	corpId : _config.corpId,
	timeStamp : _config.timeStamp,
	nonceStr : _config.nonceStr,
	signature : _config.signature,
	jsApiList : [ 'biz.contact.complexPicker','biz.customContact.choose' ]
});
if(sessionStorage.getItem("name")){
	//alert(localStorage.getItem("name"));
//	setthenum();

	onload();
}else{
	dd.ready(function() {
		//channel runtime  requestOperateAuthCode requestAuthCode
	    dd.runtime.permission.requestAuthCode({
	        corpId: _config.corpId,
	        onSuccess: function(result) {
	        	getuserId(result);
	        },
	        onFail : function(err) {
	        	alert("错误"+JSON.stringify(err))
	        }
	 
	    });
	});
	function getuserId(result){
			    //$("body").text('https://oapi.dingtalk.com/user/getuserinfo?code=' + result.code + '&access_token='+ _config.token);
		$.ajax({
			url : '../../dingding/ddEasy',
			type : 'POST',
			data:JSON.stringify({"code":result.code,"token":_config.token}),
			contentType: "application/json; charset=utf-8",
			dataType : "json",
			success : function(suc) {
			    if(suc.status == '1002'){
			    	sessionStorage.setItem("userId",suc.userJson.userid);
			    	sessionStorage.setItem("name",suc.userJson.name);
			    	sessionStorage.setItem("jobnumber",suc.userJson.jobnumber);
			    	sessionStorage.setItem("deptId",suc.userJson.department);
			    	sessionStorage.setItem("mobile",suc.userJson.mobile);
//					sendData.planuserid =sessionStorage.getItem("userId");
//					setthenum();
			    	onload();
			    }else{
			    	layer.alert(suc.msg);
			    }

			},
			error : function(xhr, errorType, error) {
					alert(errorType + ', ' + error);
				}
		});
	}
	dd.error(function(err) {
		alert('dd error: ' + JSON.stringify(err));
	});
}
function onload(){  //界面切换
	$('#name').text(sessionStorage.getItem("name"));
 	if(sessionStorage.getItem("Creload")=='true'){
	     window.location.reload();
		 sessionStorage.setItem("Creload", false);
	}else{
		
		addClick();
		getPandianJiancha();
		getPandianJianShopDaibanList();
		getPandianJianBipan();
		getPandianJianchaChanggui();
		getPandianJianchaZicai();
		getBuhegeBiaozhun();
		getPandianJianchaWentifankui();
		getPandianHuifu();
		getPandianPingjia();
//		if(type != 'zongjie'){
//			getPandianHuifu();
//		}
  }
	
};
//查询门店盘点信息
function getPandianJiancha(){
	var sendData = {};
	sendData.id=pandianid;
	$.ajax({
		url: "../pandianevery_jd/getPandianJiancha"
		,type:'post'
		,async: false
		,data:JSON.stringify(sendData)
		,contentType: "application/json; charset=utf-8"
		,dataType:'json'
		,success: function(res){
			console.log(res)
			$('#dataTable').empty();
			$('#querenTable').empty();
			if(res.success){
				var resdata = res.data[0];
				pandianLevel = resdata.level;
				everyId = resdata.biaozhunid;
				shopcode = resdata.shopcode;
				$('#dataTable').append('<tr class="thin-border-bottom">'
						+'	<td>门店编号</td>'
						+'	<td style="" class="">'+resdata.shopcode+'</td>'
						+'</tr>');
				$('#dataTable').append('<tr class="thin-border-bottom">'
						+'	<td>门店名称</td>'
						+'	<td style="" class="">'+resdata.shopname+'</td>'
						+'</tr>');
				$('#dataTable').append('<tr class="thin-border-bottom">'
						+'	<td>盘点日期</td>'
						+'	<td style="" class="">'+resdata.pandianDate+'</td>'
						+'</tr>');
				addPandianJiancha(resdata)
			}else{
//				layer.alert(res.message);
			}
		}
		,error:function(XMLHttpRequest, textStatus, errorThrown) {
			 console.log(XMLHttpRequest);
			 console.log(textStatus);
			 console.log(errorThrown);
			 hideloading();
		}
	});
	
}
function addPandianJiancha(jsonparse){
	$('#querenTable').append('<div class="col_box">'
			+'		<div class="widget-box add_mar_tb7p">'
			+'			<div class="widget-header widget-header-flat widget-header-small add_pad_tb10p add_bor_tbgrey">'				
			+'				<h5><i class="iconfont">&#xe600;</i>&nbsp;审批内容</h5><span class="red"></span>'						  
			+'			</div>'				
			+'			<div class="widget-body zhediebox1">'					
			+'				<div class="widget-main pd_div" style="padding:0;">'					
			+'					<div class="clearfix jy_div" style="padding:0;">'						
			+'						<textarea readonly rows="" cols="" class="pull-left add_pad_tb10p add_bor_none">'+(jsonparse.querenRemark==undefined?"":jsonparse.querenRemark)+'</textarea>'								
			+'					</div>'						
			+'				</div>'						
			+'			</div>'					
			+'		</div>'					
			+'</div>');
	
}
//查询门店代办事项
function getPandianJianShopDaibanList(){
	var sendData = {};
	sendData.pandianid=pandianid;
	$.ajax({
		url: "../pandianevery_jd/getPandianJianShopDaibanList"
		,type:'post'
//		,async: false
		,data:JSON.stringify(sendData)
		,contentType: "application/json; charset=utf-8"
		,dataType:'json'
		,success: function(res){
			console.log(res)
			$('#daibanTable').empty();
			if(res.success){
				var resdata = res.data;
				for (var i = 0; i < resdata.length; i++) {
					$('#daibanTable').append('<tr class="thin-border-bottom">'
							+'	<td>'+resdata[i].itemname+'</td>'
							+'	<td style="" class="">'+(resdata[i].checkValue==undefined?"":resdata[i].checkValue)+'</td>'
							+'</tr>');
				}
			}else{
//				layer.alert(res.message);
			}
		}
		,error:function(XMLHttpRequest, textStatus, errorThrown) {
			 console.log(XMLHttpRequest);
			 console.log(textStatus);
			 console.log(errorThrown);
			 hideloading();
		}
	});
	
}
//查询必盘项
function getPandianJianBipan(){
	var sendData = {};
	sendData.pandianid=pandianid;
	$.ajax({
		url: "../pandianevery_jd/getPandianJianBipan"
		,type:'post'
//		,async: false
		,data:JSON.stringify(sendData)
		,contentType: "application/json; charset=utf-8"
		,dataType:'json'
		,success: function(res){
			console.log(res)
			$('#bipanTable').empty();
			if(res.success){
				var resdata = res.data;
				for (var i = 0; i < resdata.length; i++) {
					$('#bipanTable').append('<tr class="thin-border-bottom">'
							+'	<td>'+resdata[i].itemname+'</td>'
							+'	<td style="" class="">'+resdata[i].optionname+'</td>'
							+'</tr>');
				}
			}else{
//				layer.alert(res.message);
			}
		}
		,error:function(XMLHttpRequest, textStatus, errorThrown) {
			 console.log(XMLHttpRequest);
			 console.log(textStatus);
			 console.log(errorThrown);
			 hideloading();
		}
	});
	
}
//查询资材盘点
function getPandianJianchaZicai(){
	var sendData = {};
	sendData.pandianid=pandianid;
	sendData.chayi = true;
	$.ajax({
		url: "../pandianevery_jd/getPandianJianchaZicai"
		,type:'post'
//		,async: false
		,data:JSON.stringify(sendData)
		,contentType: "application/json; charset=utf-8"
		,dataType:'json'
		,success: function(res){
			console.log(res)
			$('#zicaiTable').empty();
			if(res.success){
				var resdata = res.data;
				for (var i = 0; i < resdata.length; i++) {
					$('#zicaiTable').append('<tr class="thin-border-bottom">'
							+'	<td>'+resdata[i].gdsname+'</td>'
							+'	<td>'+resdata[i].sysnum+'</td>'
							+'	<td>'+resdata[i].pandiannum+'</td>'
							+'	<td style="" class="">'+resdata[i].chayinum+'</td>'
							+'</tr>');
				}
			}else{
//				layer.alert(res.message);
			}
		}
		,error:function(XMLHttpRequest, textStatus, errorThrown) {
			 console.log(XMLHttpRequest);
			 console.log(textStatus);
			 console.log(errorThrown);
			 hideloading();
		}
	});
	
}
//查询常规盘点
function getPandianJianchaChanggui(){
	var sendData = {};
	sendData.pandianid=pandianid;
	$.ajax({
		url: "../pandianevery_jd/getPandianJianchaChanggui"
		,type:'post'
//		,async: false
		,data:JSON.stringify(sendData)
		,contentType: "application/json; charset=utf-8"
		,dataType:'json'
		,success: function(res){
			console.log(res)
			$('#changguiTable').empty();
			if(res.success){
				var resdata = res.data;
				for (var i = 0; i < resdata.length; i++) {
					$('#changguiTable').append('<tr class="thin-border-bottom">'
							+'	<td class="td_left">'+resdata[i].biaozhunname+'</td>'
							+'	<td style="" class="">'+resdata[i].biaozhunvalue+'</td>'
							+'</tr>');
				}
			}else{
//				layer.alert(res.message);
			}
		}
		,error:function(XMLHttpRequest, textStatus, errorThrown) {
			 console.log(XMLHttpRequest);
			 console.log(textStatus);
			 console.log(errorThrown);
			 hideloading();
		}
	});
	
}
////查询盘点回复信息
//function getPandianHuifu(){
//	var sendData = {};
//	sendData.pandianid=pandianid;
//	$.ajax({
//		url: "../pandianevery_jd/getPandianHuifu"
//		,type:'post'
////		,async: false
//		,data:JSON.stringify(sendData)
//		,contentType: "application/json; charset=utf-8"
//		,dataType:'json'
//		,success: function(res){
//			console.log(res)
//			$('#dataTable').empty();
//			if(res.success){
//				var resdata = res.data[0];
//				if(resdata.zongjiecontent != undefined){
//					$('#zongjiecontent').val(resdata.zongjiecontent);
//				}
//				if(resdata.huifuremark != undefined){
//					$('#huifuremark').val(resdata.huifuremark);
//				}
//			}else{
////				layer.alert(res.message);
//			}
//		}
//		,error:function(XMLHttpRequest, textStatus, errorThrown) {
//			 console.log(XMLHttpRequest);
//			 console.log(textStatus);
//			 console.log(errorThrown);
//			 hideloading();
//		}
//	});
//	
//}

//查询标准不合格项
function getBuhegeBiaozhun(){
	var sendData = {};
	sendData.everyId=everyId;
	$.ajax({
		url: "../pandianevery_jd/getBuhegeBiaozhun"
		,type:'post'
//		,async: false
		,data:JSON.stringify(sendData)
		,contentType: "application/json; charset=utf-8"
		,dataType:'json'
		,success: function(res){
			console.log(res)
			$('#biaozhunTable').empty();
			if(res.success){
				var resdata = res.data;
				addBuhegeBiaozhun(resdata);
			}else{
//				layer.alert(res.message);
			}
		}
		,error:function(XMLHttpRequest, textStatus, errorThrown) {
			 console.log(XMLHttpRequest);
			 console.log(textStatus);
			 console.log(errorThrown);
			 hideloading();
		}
	});
	
}
function addBuhegeBiaozhun(jsonparse){
	for(var i = 0 ;i<jsonparse.length;i++){
		var imgStr = '';
		var imgJson = typeof jsonparse[i].photo == 'string'?JSON.parse(jsonparse[i].photo):jsonparse[i].photo;
		if (imgJson.length > 0) {
			var imgOne='';
			for (var j = 0; j < imgJson.length; j++) {
				imgOne += '<div class="wig_img">'
					+'<div class="img_box">'
					+'<img wentiimg alt="100x100" src="'+imgJson[j]+'" onclick="showAllPic(\''+imgJson[j]+'\')"/>'
					+'</div>'
					+'</div>';
			}
			imgStr = '		<div class="widget-box add_mar_tb7p">'
					+'			<div class="widget-header widget-header-flat widget-header-small add_pad_tb10p add_bor_tbgrey">'				
					+'				<h5><i class="iconfont">&#xe600;</i>&nbsp;图片</h5><span class="red"></span>'						  
					+'			</div>'				
					+'			<div class="widget-body zhediebox1">'					
					+'				<div class="widget-main pd_div" id="paizhapoUrl'+jsonparse[i].id+'" >'
					+imgOne
					+'					<div class="clearfix"></div>'						
					+'				</div>'						
					+'			</div>'					
					+'		</div>';
		}
		var thenum = $('div[itemDiv]').length;
		$('#biaozhunTable').append('<div class="col_box" itemDiv="'+jsonparse[i].id+'">'
//				+'<div class="widget-header widget-header-flat widget-header-small add_pad_tb10p add_mar_tb7p">'
//				+'<h5 id="wentishuomingTitle" class="black">必盘项'+(thenum+1)+'</h5>'
//				+'<div deleteIndex="'+thenum+'" class="bt_delete bg_orange">删除</div><div class="clearfix"></div>'
//				+'</div>'
				+'		<div class="widget-box add_mar_tb7p">'
				+'			<div class="widget-header widget-header-flat widget-header-small add_pad_tb10p add_bor_tbgrey">'
				+'				<h5><i class="iconfont">&#xe600;</i>&nbsp;条款'+(thenum+1)+'</h5><span class="red" bitian></span>'
				+'				<div class="pull-right add_bor_none" style="width: 70%;margin-right: 2%; color:#474747; line-height:26px;">'+jsonparse[i].item+'</div>'
				+'			</div>'
				+'		</div>'
				+'		<div class="widget-box add_mar_tb7p">'
				+'			<div class="widget-header widget-header-flat widget-header-small add_pad_tb10p add_bor_tbgrey">'
				+'				<h5><i class="iconfont">&#xe600;</i>&nbsp;选择</h5><span class="red" bitian></span>'
				+'				<input type="text" value="'+jsonparse[i].option+'" readonly autocomplete="off"   class="pull-right add_bor_none" style="width: 70%;margin-right: 2%"/>'
				+'			</div>'
				+'		</div>'
//				+'		<div class="widget-box add_mar_tb7p">'
//				+'			<div class="widget-header widget-header-flat widget-header-small add_pad_tb10p add_bor_tbgrey">'
//				+'				<h5><i class="iconfont">&#xe600;</i>&nbsp;备注</h5><span class="red" bitian></span>'
//				+'				<input type="text" placeholder="请输入备注" jsonKey="remark" autocomplete="off"   class="pull-right add_bor_none" style="width: 70%;margin-right: 2%"/>'
//				+'			</div>'
//				+'		</div>'
				+imgStr
//				+'<input type="hidden" value="'+jsonparse[i].id+'" jsonKey="id"/>'
//				+'<div editIndex="'+thenum+'" class="bt_delete bg_blue">编辑</div><div class="clearfix"></div>'					
				+'</div>');
	
	}
}
//查询问题反馈
function getPandianJianchaWentifankui(){
	var sendData = {};
	sendData.pandianid=pandianid;
	$.ajax({
		url: "../pandianevery_jd/getPandianJianchaWentifankui"
		,type:'post'
//		,async: false
		,data:JSON.stringify(sendData)
		,contentType: "application/json; charset=utf-8"
		,dataType:'json'
		,success: function(res){
			console.log(res)
			$('#fankuiTable').empty();
			if(res.success){
				var resdata = res.data;
				addPandianJianchaWentifankui(resdata);
			}else{
//				layer.alert(res.message);
			}
		}
		,error:function(XMLHttpRequest, textStatus, errorThrown) {
			 console.log(XMLHttpRequest);
			 console.log(textStatus);
			 console.log(errorThrown);
			 hideloading();
		}
	});
	
}
function addPandianJianchaWentifankui(jsonparse){
	var zhidu = 'readonly';
	if(type == 'queren'){
		zhidu = '';
	}
	for(var i = 0 ;i<jsonparse.length;i++){
		var imgStr = '';
		var imgJson = typeof jsonparse[i].imgurl == 'string'?JSON.parse(jsonparse[i].imgurl):jsonparse[i].imgurl;
		if (imgJson.length > 0) {
			var imgOne='';
			for (var j = 0; j < imgJson.length; j++) {
				imgOne += '<div class="wig_img">'
					+'<div class="img_box">'
					+'<img wentiimg alt="100x100" src="'+imgJson[j]+'" onclick="showAllPic(\''+imgJson[j]+'\')"/>'
					+'</div>'
					+'</div>';
			}
			imgStr = '		<div class="widget-box add_mar_tb7p">'
					+'			<div class="widget-header widget-header-flat widget-header-small add_pad_tb10p add_bor_tbgrey">'				
					+'				<h5><i class="iconfont">&#xe600;</i>&nbsp;图片</h5><span class="red"></span>'						  
					+'			</div>'				
					+'			<div class="widget-body zhediebox1">'					
					+'				<div class="widget-main pd_div" id="paizhapoUrl'+jsonparse[i].id+'" >'
					+imgOne
					+'					<div class="clearfix"></div>'						
					+'				</div>'						
					+'			</div>'					
					+'		</div>';
		}
		var thenum = $('div[itemDiv]').length;
		var querenStr='';
		if(type != 'queren'){
			querenStr += '		<div class="widget-box add_mar_tb7p">'
						+'			<div class="widget-header widget-header-flat widget-header-small add_pad_tb10p add_bor_tbgrey">'				
						+'				<h5><i class="iconfont">&#xe600;</i>&nbsp;回复内容</h5><span class="red"></span>'						  
						+'			</div>'				
						+'			<div class="widget-body zhediebox1">'					
						+'				<div class="widget-main pd_div" style="padding:0;">'					
						+'					<div class="clearfix jy_div" style="padding:0;">'						
						+'						<textarea readonly rows="6" cols="" class="pull-left add_pad_tb10p add_bor_none">'+(jsonparse[i].huifu==undefined?"":jsonparse[i].huifu)+'</textarea>'								
						+'					</div>'						
						+'				</div>'						
						+'			</div>'					
						+'		</div>'
						+'		<div class="widget-box add_mar_tb7p">'
						+'			<div class="widget-header widget-header-flat widget-header-small add_pad_tb10p add_bor_tbgrey">'
						+'				<h5><i class="iconfont">&#xe600;</i>&nbsp;完成人</h5><span class="red" bitian></span>'
						+'				<input type="hidden" jsonKey="wanchenguser" value="'+jsonparse[i].wanchenguser+'"/>'
						+'				<input type="text" jsonKey="wanchengusername" value="'+jsonparse[i].wanchengusername+'" readonly autocomplete="off"   class="pull-right add_bor_none" style="width: 70%;margin-right: 2%"/>'
						+'			</div>'
						+'		</div>'	
						+'		<div class="widget-box add_mar_tb7p">'
						+'			<div class="widget-header widget-header-flat widget-header-small add_pad_tb10p add_bor_tbgrey">'
						+'				<h5><i class="iconfont">&#xe600;</i>&nbsp;完成时间</h5><span class="red" bitian></span>'
						+'				<input type="text" jsonKey="wanchengDate" value="'+jsonparse[i].wanchengDate+'" readonly autocomplete="off"   class="pull-right add_bor_none" style="width: 70%;margin-right: 2%"/>'
						+'			</div>'
						+'		</div>'	
		}
		$('#fankuiTable').append('<div class="col_box" itemDiv="'+jsonparse[i].id+'">'
//				+'<div class="widget-header widget-header-flat widget-header-small add_pad_tb10p add_mar_tb7p">'
//				+'<h5 id="wentishuomingTitle" class="black">必盘项'+(thenum+1)+'</h5>'
//				+'<div deleteIndex="'+thenum+'" class="bt_delete bg_orange">删除</div><div class="clearfix"></div>'
//				+'</div>'
				+'		<div class="widget-box add_mar_tb7p">'
				+'			<div class="widget-header widget-header-flat widget-header-small add_pad_tb10p add_bor_tbgrey">'
				+'				<h5><i class="iconfont">&#xe600;</i>&nbsp;问题'+(thenum+1)+'</h5><span class="red" bitian></span>'
//				+'				<input type="text" jsonKey="wenti" oldValue="'+jsonparse[i].wenti+'" value="'+jsonparse[i].wenti+'" '+zhidu+' autocomplete="off" class="pull-right add_bor_none" style="width: 70%;margin-right: 2%"/>'
				+'			</div>'
				+'			<div class="widget-body zhediebox1">'					
				+'				<div class="widget-main pd_div" style="padding:0;">'					
				+'					<div class="clearfix jy_div" style="padding:0;">'						
				+'						<textarea id="wenti'+thenum+'" oldValue="'+jsonparse[i].wenti+'" rows="6" jsonKey="wenti" '+zhidu+' name="wenti'+thenum+'" class="pull-left add_pad_tb10p add_bor_none" placeholder="输入问题说明">'+jsonparse[i].wenti+'</textarea>'								
				+'					</div>'						
				+'				</div>'						
				+'			</div>'
				+'		</div>'
				+imgStr
				+'		<div class="widget-box add_mar_tb7p">'
				+'			<div class="widget-header widget-header-flat widget-header-small add_pad_tb10p add_bor_tbgrey">'
				+'				<h5><i class="iconfont">&#xe600;</i>&nbsp;回复人</h5><span class="red" bitian></span>'
				+'				<input type="hidden" jsonKey="senduser" oldValue="'+jsonparse[i].senduser+'" value="'+jsonparse[i].senduser+'"/>'
				+'				<input type="text" jsonKey="sendusername" value="'+jsonparse[i].sendusername+'" onclick="openDingdingUser('+jsonparse[i].id+',this)" readonly autocomplete="off"   class="pull-right add_bor_none" style="width: 70%;margin-right: 2%"/>'
				+'			</div>'
				+'		</div>'	
				+querenStr
//				+'		<div class="widget-box add_mar_tb7p">'
//				+'			<div class="widget-header widget-header-flat widget-header-small add_pad_tb10p add_bor_tbgrey">'
//				+'				<h5><i class="iconfont">&#xe600;</i>&nbsp;备注</h5><span class="red" bitian></span>'
//				+'				<input type="text" placeholder="请输入备注" jsonKey="remark" autocomplete="off"   class="pull-right add_bor_none" style="width: 70%;margin-right: 2%"/>'
//				+'			</div>'
//				+'		</div>'
//				+'<input type="hidden" value="'+jsonparse[i].id+'" jsonKey="id"/>'
//				+'<div editIndex="'+thenum+'" class="bt_delete bg_blue">编辑</div><div class="clearfix"></div>'					
				+'</div>');
	
	}
}
//查询盘点回复和总结
function getPandianHuifu(){
	var sendData = {};
	sendData.pandianid=pandianid;
	$.ajax({
		url: "../pandianevery_jd/getPandianHuifu"
		,type:'post'
//		,async: false
		,data:JSON.stringify(sendData)
		,contentType: "application/json; charset=utf-8"
		,dataType:'json'
		,success: function(res){
			console.log(res)
			$('#zongjieTable').empty();
			$('#huifuTable').empty();
			if(res.success){
				var resdata = res.data;
				addPandianHuifu(resdata);
				if(sessionStorage.getItem("jobnumber") != resdata[0].huifuuserjobnumber){
					$('#pingjiaDiv').hide();
				}
				if(resdata[0].zongjiecontent != undefined){
					$('#zongjiecontent').val(resdata[0].zongjiecontent);
				}
				if(resdata[0].huifuremark != undefined){
					$('#huifuremark').val(resdata[0].huifuremark);
				}
				if(type == 'huifu' && resdata[0].huifuFlag == 1){
					$('#buttonDiv').hide();
				}
				if(type == 'zongjie' && resdata[0].zongjieFlag == 1){
					$('#buttonDiv').hide();
				}
			}else{
//				layer.alert(res.message);
			}
		}
		,error:function(XMLHttpRequest, textStatus, errorThrown) {
			 console.log(XMLHttpRequest);
			 console.log(textStatus);
			 console.log(errorThrown);
			 hideloading();
		}
	});
	
}

function addPandianHuifu(jsonparse){
	for(var i = 0 ;i<jsonparse.length;i++){
//		var imgStr = '';
//		var imgJson = typeof jsonparse[i].imgurl == 'string'?JSON.parse(jsonparse[i].imgurl):jsonparse[i].imgurl;
//		if (imgJson.length > 0) {
//			var imgOne='';
//			for (var j = 0; j < imgJson.length; j++) {
//				imgOne += '<div class="wig_img">'
//					+'<div class="img_box">'
//					+'<img wentiimg alt="100x100" src="'+imgJson[j]+'" onclick="showAllPic(\''+imgJson[j]+'\')"/>'
//					+'</div>'
//					+'</div>';
//			}
//			imgStr = '		<div class="widget-box add_mar_tb7p">'
//					+'			<div class="widget-header widget-header-flat widget-header-small add_pad_tb10p add_bor_tbgrey">'				
//					+'				<h5><i class="iconfont">&#xe600;</i>&nbsp;图片</h5><span class="red"></span>'						  
//					+'			</div>'				
//					+'			<div class="widget-body zhediebox1">'					
//					+'				<div class="widget-main pd_div" id="paizhapoUrl'+jsonparse[i].id+'" >'
//					+imgOne
//					+'					<div class="clearfix"></div>'						
//					+'				</div>'						
//					+'			</div>'					
//					+'		</div>';
//		}
		$('#huifuTable').append('<div class="col_box">'
				+'		<div class="widget-box add_mar_tb7p">'
				+'			<div class="widget-header widget-header-flat widget-header-small add_pad_tb10p add_bor_tbgrey">'
				+'				<h5><i class="iconfont">&#xe600;</i>&nbsp;回复人</h5><span class="red" bitian></span>'
				+'				<input type="text" value="'+jsonparse[i].huifuusername+'" readonly autocomplete="off"   class="pull-right add_bor_none" style="width: 70%;margin-right: 2%"/>'
				+'			</div>'
				+'		</div>'
				+'		<div class="widget-box add_mar_tb7p">'
				+'			<div class="widget-header widget-header-flat widget-header-small add_pad_tb10p add_bor_tbgrey">'				
				+'				<h5><i class="iconfont">&#xe600;</i>&nbsp;回复内容</h5><span class="red"></span>'						  
				+'			</div>'				
				+'			<div class="widget-body zhediebox1">'					
				+'				<div class="widget-main pd_div" style="padding:0;">'					
				+'					<div class="clearfix jy_div" style="padding:0;">'						
				+'						<textarea readonly rows="" cols="" class="pull-left add_pad_tb10p add_bor_none">'+jsonparse[i].huifuremark+'</textarea>'								
				+'					</div>'						
				+'				</div>'						
				+'			</div>'					
				+'		</div>'					
				+'</div>');
		$('#zongjieTable').append('<div class="col_box">'
				+'		<div class="widget-box add_mar_tb7p">'
				+'			<div class="widget-header widget-header-flat widget-header-small add_pad_tb10p add_bor_tbgrey">'
				+'				<h5><i class="iconfont">&#xe600;</i>&nbsp;总结人</h5><span class="red" bitian></span>'
				+'				<input type="text" value="'+jsonparse[i].zongjieusername+'" readonly autocomplete="off"   class="pull-right add_bor_none" style="width: 70%;margin-right: 2%"/>'
				+'			</div>'
				+'		</div>'
				+'		<div class="widget-box add_mar_tb7p">'
				+'			<div class="widget-header widget-header-flat widget-header-small add_pad_tb10p add_bor_tbgrey">'				
				+'				<h5><i class="iconfont">&#xe600;</i>&nbsp;总结内容</h5><span class="red"></span>'						  
				+'			</div>'				
				+'			<div class="widget-body zhediebox1">'					
				+'				<div class="widget-main pd_div" style="padding:0;">'					
				+'					<div class="clearfix jy_div" style="padding:0;">'						
				+'						<textarea readonly rows="" cols="" class="pull-left add_pad_tb10p add_bor_none">'+(jsonparse[i].zongjiecontent==undefined?"":jsonparse[i].zongjiecontent)+'</textarea>'								
				+'					</div>'						
				+'				</div>'						
				+'			</div>'					
				+'		</div>'					
				+'</div>');
	
	}
}
//查询门店评价
function getPandianPingjia(){
	$.ajax({  
		url: "../pandianevery_jd/getPandianJianchaPingjia"
		,type:'post'
		,async: false
		,contentType: "application/json; charset=utf-8"
		,data:JSON.stringify({"pandianid":pandianid}) 
		,dataType:'json'
		,success: function(res){
			try {
				$('#shoppingjiaTable').empty();
				if(res.success){
					var data = res.data;
					addPingjiaItem(data);
				}else{
					layer.msg(res.message);
				}
			} catch (e) {
				console.log(e)
			} finally{
				hideloading();
			}
		}
	});
}
function addPingjiaItem(jsonparse){
	var itemStr = '';
//	$('#shoppingjiaTable').append('<div class="col_box">');
	for(var i = 0 ;i<jsonparse.length;i++){
		var id = jsonparse[i].pingjiaitem;
		$('#shoppingjiaTable').append('		<div class="widget-box add_mar_tb7p">'
			+'			<div class="widget-header widget-header-flat widget-header-small add_pad_tb10p add_bor_tbgrey">'
			+'				<h5><i class="iconfont">&#xe600;</i>&nbsp;'+jsonparse[i].pingjiaitemname+'</h5><span class="red" bitian></span>'
			+'				<div id="star'+id+'" sort="'+jsonparse[i].sort+'" jsonKey="pingjiaitem" pingjiaitem="'+id+'" pingjiaitemname="'+jsonparse[i].pingjiaitemname+'" pingjiaitemscore="'+jsonparse[i].pingjiaitemscore+'" pingjiascore="0" class="pull-right add_bor_none" style="width: 50%;margin-right: 2%; color:#474747; line-height:26px;">'
			+'				</div>'
			+'			</div>'
			+'		</div>');
		if(jsonparse[i].pingjiascore == undefined){
			rate.render({
				elem: '#star'+id
				,text: false
				,choose: function(value){
					var key = this.elem.selector;
					$(key).attr('pingjiascore',value);
				}
			})
		}else{
			rate.render({
				elem: '#star'+id
				,text: false
				,readonly: true
				,value:jsonparse[i].pingjiascore
			})
		}
	}
	$('#shoppingjiaTable').append('		<div class="widget-box add_mar_tb7p">'
						+'			<div class="widget-header widget-header-flat widget-header-small add_pad_tb10p add_bor_tbgrey">'				
						+'				<h5><i class="iconfont">&#xe600;</i>&nbsp;评价内容</h5><span class="red"></span>'						  
						+'			</div>'				
						+'			<div class="widget-body zhediebox1">'					
						+'				<div class="widget-main pd_div" style="padding:0;">'					
						+'					<div class="clearfix jy_div" style="padding:0;">'						
						+'						<textarea id="pingjiaremark" readonly jsonKey="pingjiaremark" name="pingjiaremark" rows="" cols="" class="pull-left add_pad_tb10p add_bor_none"></textarea>'								
						+'					</div>'						
						+'				</div>'						
						+'			</div>'					
						+'		</div>');
	if(jsonparse[0] != undefined && jsonparse[0].pingjiaremark != undefined){
		$('#pingjiaremark').val(jsonparse[0].pingjiaremark);
	}
}
//打开钉钉人员选择
function openDingdingUser(index,obj){
	dd.ready(function(){
//		dd.biz.contact.complexPicker({
//		    title:"选择发送人",            //标题
//		    corpId:"ding747ef67afb96e34835c2f4657eb6378f",              //企业的corpId _config.corpId
//		    multiple:false,            //是否多选
//		    limitTips:"只能选择1个",          //超过限定人数返回提示
//		    maxUsers:1,            //最大可选人数
//		    pickedUsers:[],            //已选用户
//		    pickedDepartments:[],          //已选部门
//		    disabledUsers:[],            //不可选用户
//		    disabledDepartments:[],        //不可选部门
//		    requiredUsers:[],            //必选用户（不可取消选中状态）
//		    requiredDepartments:[],        //必选部门（不可取消选中状态）
//		    appId:276769340,              //微应用的Id _config.appid
//		    permissionType:"GLOBAL",          //可添加权限校验，选人权限，目前只有GLOBAL这个参数
//		    responseUserOnly:true,        //返回人，或者返回人和部门
//		    startWithDepartmentId:0 ,   //仅支持0和-1
//		    onSuccess: function(result) {
//		    	$(obj).parent().find('input[jsonKey="senduser"]').val(result.users[0].emplId);
//		    	$(obj).parent().find('input[jsonKey="sendusername"]').val(result.users[0].name);
//		        /**
//		        {
//		            selectedCount:1,                              //选择人数
//		            users:[{"name":"","avatar":"","emplId":""}]，//返回选人的列表，列表中的对象包含name（用户名），avatar（用户头像），emplId（用户工号）三个字段
//		            departments:[{"id":,"name":"","number":}]//返回已选部门列表，列表中每个对象包含id（部门id）、name（部门名称）、number（部门人数）
//		        }
//		        */
//		    },
//		   onFail : function(err) {
//			   alert(JSON.stringify(err));
//			   
//		   }
//		});
		dd.biz.customContact.choose({
		    title: '选择发送人', //标题
		    users: ['1551256127854625'
		            ,'161567154238057731'
		            ,'124515441122792191'
		            ,'41555139940020'
		            ,'0151312504-2099498898'
		            ,'415446271143578'
		            ,'41561066917147328'
		            ,'182211353327333045'],//一组员工userid
		    corpId: 'ding747ef67afb96e34835c2f4657eb6378f',//加密的企业 ID，
		    isShowCompanyName: true,   //true|false，默认为 false
//		    disabledUsers: ["78308"], //不能选的人
		    onSuccess: function(result) {
		    	$(obj).parent().find('input[jsonKey="senduser"]').val(result[0].emplId);
		    	$(obj).parent().find('input[jsonKey="sendusername"]').val(result[0].name);
		    /* data结构
		      [{
		        "name": "张三", //姓名
		        "avatar": "http://g.alicdn.com/avatar/zhangsan.png" //头像图片url，可能为空
		        "emplId": '0573', //即员工userId，[<font color=red>获取成员详情接口</font>](https://open-doc.dingtalk.com/docs/doc.htm?spm=a219a.7629140.0.0.DHPTF8&treeId=385&articleId=106816&docType=1#s1)

		       },
		       ...
		      ]
		    */
		    },
		    onFail : function(err) {}
		});
	});
	dd.error(function(err) {
		alert(JSON.stringify(err));
		
//		alert('dd error: ' + JSON.stringify(err));
	});
}
function addClick(){
	if(type == 'queren'){
		$('#buttonDiv').append('<div onclick="queren(1)" style="width: 49%;margin-right: 2%;float: left;" class="submit_button">同意</div>');
		$('#buttonDiv').append('<div onclick="queren(2)" style="width: 49%;float: right;" class="submit_button">拒绝</div>');
		$('#buttonDiv').show();
//		$('#buttonDiv').off('click');
//		$('#buttonDiv').on('click',function(){
//			queren()
//		});
		$('#pingjiaDiv').append('		<div class="widget-box add_mar_tb7p">'
				+'			<div class="widget-header widget-header-flat widget-header-small add_pad_tb10p add_bor_tbgrey">'				
				+'				<h5><i class="iconfont">&#xe600;</i>&nbsp;盘点审批</h5><span class="red"></span>'						  
				+'			</div>'				
				+'			<div class="widget-body zhediebox1">'					
				+'				<div class="widget-main pd_div" style="padding:0;">'					
				+'					<div class="clearfix jy_div" style="padding:0;">'						
				+'						<textarea id="querenRemark" name="querenRemark" rows="" cols="" class="pull-left add_pad_tb10p add_bor_none" placeholder="请输入理由"></textarea>'								
				+'					</div>'						
				+'				</div>'						
				+'			</div>'					
				+'		</div>'			
				+'</div>');
		$('#pingjiaDiv').show();
		$('div[tableDiv="querenDiv"]').hide();
		$('div[tableDiv="zongjieDiv"]').hide();
		$('div[tableDiv="huifuDiv"]').hide();
		$('div[tableDiv="shoppingjiaDiv"]').hide();
		//input[jsonKey="huifuusername"],input[jsonKey="huifuuser"],
//		$('#fankuiTable').find('input[jsonKey="wenti"]').removeAttr('readonly')
	}else if(type=='zongjie'){
		$('#buttonDiv').append('<div class="submit_button w94">总结</div>');
		$('#buttonDiv').show();
		$('#buttonDiv').off('click');
		$('#buttonDiv').on('click',zongjie);
		$('#pingjiaDiv').append('		<div class="widget-box add_mar_tb7p">'
						+'			<div class="widget-header widget-header-flat widget-header-small add_pad_tb10p add_bor_tbgrey">'				
						+'				<h5><i class="iconfont">&#xe600;</i>&nbsp;盘点总结</h5><span class="red"></span>'						  
						+'			</div>'				
						+'			<div class="widget-body zhediebox1">'					
						+'				<div class="widget-main pd_div" style="padding:0;">'					
						+'					<div class="clearfix jy_div" style="padding:0;">'						
						+'						<textarea id="zongjiecontent" name="zongjiecontent" rows="" cols="" class="pull-left add_pad_tb10p add_bor_none" placeholder="输入盘点总结"></textarea>'								
						+'					</div>'						
						+'				</div>'						
						+'			</div>'					
						+'		</div>'			
						+'</div>');
		$('#pingjiaDiv').show();
		$('div[tableDiv="zongjieDiv"]').hide();
		$('div[tableDiv="huifuDiv"]').hide();
		$('div[tableDiv="shoppingjiaDiv"]').hide();
	}else if(type=='huifu'){
		$('#buttonDiv').append('<div class="submit_button w94">回复</div>');
		$('#buttonDiv').show();
		$('#buttonDiv').off('click');
		$('#buttonDiv').on('click',huifu);
		$('#pingjiaDiv').append('		<div class="widget-box add_mar_tb7p">'
						+'			<div class="widget-header widget-header-flat widget-header-small add_pad_tb10p add_bor_tbgrey">'				
						+'				<h5><i class="iconfont">&#xe600;</i>&nbsp;回复内容</h5><span class="red"></span>'						  
						+'			</div>'				
						+'			<div class="widget-body zhediebox1">'					
						+'				<div class="widget-main pd_div" style="padding:0;">'					
						+'					<div class="clearfix jy_div" style="padding:0;">'						
						+'						<textarea id="huifuremark" name="huifuremark" rows="" cols="" class="pull-left add_pad_tb10p add_bor_none" placeholder="输入回复内容"></textarea>'								
						+'					</div>'						
						+'				</div>'						
						+'			</div>'					
						+'		</div>'			
						+'</div>');
		$('#pingjiaDiv').show();
		$('div[tableDiv="huifuDiv"]').hide();
		$('div[tableDiv="shoppingjiaDiv"]').hide();
	}else{
		$('#buttonDiv').hide();
		$('#pingjiaDiv').hide();
	}
}

function queren(querenFlag){
	showloading();
	var sendData = {};
	sendData.querenFlag = querenFlag;
	sendData.id = pandianid;
	sendData.level = pandianLevel;
	sendData.querenRemark = $('#querenRemark').val();
	var huifuUser = [];
	var wentiArray = [];
	if(querenFlag == 2){
		sendData.flag = 5;
		$('#fankuiTable div[itemDiv]').each(function(i,obj){
			var wentiOne = {};
			wentiOne.shenpiFlag = 1;
			wentiOne.id = $(obj).attr('itemDiv');
			wentiArray.push(wentiOne);
		});
	}else{
		sendData.flag = 6;
		//同意做出是否修改的判定
		$('#fankuiTable div[itemDiv]').each(function(i,obj){
			var wentiOne = {};
			var wenti = $(obj).find('textarea[jsonKey="wenti"]').val();
//			var wentiOld = $(obj).find('input[jsonKey="wenti"]').attr('oldValue');
			var senduser = $(obj).find('input[jsonKey="senduser"]').val();
//			var senduserOld = $(obj).find('input[jsonKey="senduser"]').attr('oldValue');
//			if( wenti != wentiOld || senduser != senduserOld){
//				wentiOne.id = $(obj).attr('itemDiv');
//				wentiOne.wenti = wenti;
//				wentiOne.senduser = senduser;
//				wentiOne.shenpiFlag = 0;
//				wentiOne.sendusername = $(obj).find('input[jsonKey="sendusername"]').val();
//				wentiArray.push(wentiOne);
//			}
			huifuUser.push(senduser);
			wentiOne.id = $(obj).attr('itemDiv');
			wentiOne.wenti = wenti;
			wentiOne.senduser = senduser;
			wentiOne.shenpiFlag = 0;
			wentiOne.sendusername = $(obj).find('input[jsonKey="sendusername"]').val();
			wentiArray.push(wentiOne);
		});
		sendData.flag = 6;
	}
	sendData.huifuUser = huifuUser.join(',');
	sendData.wentiArray = wentiArray;
	$.ajax({
		url: "../pandianevery_jd/updatePandianJiancha"
		,type:'post'
		,async: false
		,data:JSON.stringify(sendData)
		,contentType: "application/json; charset=utf-8"
		,dataType:'json'
		,success: function(res){
			console.log(res)
			try {
				if(res.success){
//					var resdata = res.data;
					window.location.href='toJiancha_pandian_daibanshixiang';
//					history.go(-1);
				}else{
					layer.alert(res.message);
				}
			} catch (e) {
				console.log(e);
			} finally{
				hideloading();
			}
			
		}
		,error:function(XMLHttpRequest, textStatus, errorThrown) {
			 console.log(XMLHttpRequest);
			 console.log(textStatus);
			 console.log(errorThrown);
			 hideloading();
		}
	});
}
function huifu(){
	showloading();
	var sendData = {};
	sendData.huifuremark = $('#huifuremark').val();
	sendData.pandianid = pandianid;
	sendData.shopcode = shopcode;
	sendData.huifuFlag = 1;
	sendData.pjId = sessionStorage.getItem("mobile");
	sendData.pingjiaUserName = sessionStorage.getItem("name");
//	sendData.pingjiaUserName = sessionStorage.getItem("name");
	sendData.pingjiaUser = sessionStorage.getItem("userId");
	$.ajax({
		url: "../pandianevery_jd/huifuPandian"
		,type:'post'
		,async: false
		,data:JSON.stringify(sendData)
		,contentType: "application/json; charset=utf-8"
		,dataType:'json'
		,success: function(res){
			console.log(res)
			try {
				if(res.success){
//					var resdata = res.data;
					window.location.href='toJiancha_pandian_daibanshixiang';
//					history.go(-1);
				}else{
//					layer.alert(res.message);
				}
			} catch (e) {
				console.log(e);
			} finally{
				hideloading();
			}
			
		}
		,error:function(XMLHttpRequest, textStatus, errorThrown) {
			 console.log(XMLHttpRequest);
			 console.log(textStatus);
			 console.log(errorThrown);
			 hideloading();
		}
	});
}
function zongjie(){
	showloading();
	var sendData = {};
	sendData.zongjiecontent = $('#zongjiecontent').val();
	sendData.pandianid = pandianid;
	sendData.zongjieFlag = 1;
	sendData.level = pandianLevel;
	sendData.shopcode = sessionStorage.getItem("shopcode");
	sendData.shopname = sessionStorage.getItem("shopname");
	$.ajax({
		url: "../pandianevery_jd/zongjiePandian"
		,type:'post'
		,async: false
		,data:JSON.stringify(sendData)
		,contentType: "application/json; charset=utf-8"
		,dataType:'json'
		,success: function(res){
			console.log(res)
			try {
				if(res.success){
//					var resdata = res.data;
					window.location.href='toJiancha_pandian_daibanshixiang';
//					history.go(-1);
				}else{
					layer.alert(res.message);
				}
			} catch (e) {
				console.log(e);
			} finally{
				hideloading();
			}
			
		}
		,error:function(XMLHttpRequest, textStatus, errorThrown) {
			 console.log(XMLHttpRequest);
			 console.log(textStatus);
			 console.log(errorThrown);
			 hideloading();
		}
	});
}
//跳转到评价页面
function inPingjia(pingjiaFlag){
	window.location.href='toJiancha_pingjia?pandianid='+pandianid+"&pingjiaFlag="+pingjiaFlag;
}
//预览图片
function showAllPic(imgOne){
	dd.biz.util.previewImage({
		urls: imgOne.split(','),//图片地址列表
		current: imgOne,//当前显示的图片链接
		onSuccess : function(result) {
			/**/
		},
		onFail : function(err) {}
	})
}